<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="账号" prop="account" required>
        <el-input disabled v-model="form.account" placeholder="请输入登录账号"/>
      </el-form-item>

      <el-form-item label="昵称">
        <el-input disabled v-model="form.username" placeholder="昵称"/>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.password" placeholder="登录密码"/>
      </el-form-item>
      <el-form-item label="备注">
        <el-input type="textarea" rows="3" v-model="form.remark" placeholder="用户备注"/>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
        <el-button @click="$router.push({path:'/user/index'})">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import api from '@/api/member'

export default {
  components: {},
  data() {
    return {

      form: {
        user_id: 0,
        account: '',
        username: '',
        password: '',
        remark: ''

      }
    }
  },

  mounted() {
    if (this.$route.query.hasOwnProperty('user_code')) {
      this.getData(this.$route.query.user_code)
    }
  },

  methods: {

    getData(user_code) {
      api.info({ user_code: user_code }).then((res) => {
        this.form = res.data
      })
    },

    onSubmit() {
      if (!this.form.password && !this.form.remark) {
        return this.$message.error('请输入密码或备注')
      }
      this.$confirm('确定提交吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.update({
          user_id: this.form.user_id,
          password: this.form.password,
          remark: this.form.remark
        }).then((res) => {
          this.$message({
            type: 'success',
            message: res.msg,
            duration: 500,
            onClose: () => {
              this.$router.push({ path: 'index' })
            }
          })

        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })

      })

    }
  }
}
</script>

<style scoped>
.line {
  text-align: center;
}

.editor-content {
  margin-top: 20px;
}

.article-textarea ::v-deep {

textarea {
  padding-right: 40px;
  resize: none;
  border: none;
  border-radius: 0px;
  border-bottom: 1px solid #bfcbd9;
}

}
</style>

